var {
  clickContent,
  randomUtils,
  existContent,
  fmtUtils,
  logUtils,
  clickUtils,
  timeUtils,
  swipeUtils,
} = require ('../../utils/index');
var {App} = require ('../../base/index');
var pointMap = require ('./pointMap');
var aTreasure = require ('./aTreasure');
var aWatchAd = require ('./aWatchAd');

var touTiao = new App ('今日头条', {
  interval: 6 * 60,
  maxOpenCount: 5,
});
touTiao.runTest = function () {};
touTiao.run = function () {
  if (randomUtils.possible (50, 100)) {
    logUtils.info ('开始阅读');
    this.read ();
  }
  if (randomUtils.possible (95, 100)) {
    clickUtils.clickPointMap (pointMap.首页.视频);
    logUtils.info ('开始观看视频');
    sleep (randomUtils.getRandom (5, 30, 1000));
    logUtils.info ('结束观看视频,将关闭今日头条');
  }
  clickUtils.clickPointMap (pointMap.首页.任务);
  sleep (randomUtils.getRandom (10, 15, 1000));
  if (randomUtils.possible (50, 100)) {
    aTreasure.flow ();
    this.inTask ();
    aWatchAd.flow ();
  } else {
    aWatchAd.flow ();
    this.inTask ();
    aTreasure.flow ();
  }
  sleep (randomUtils.getRandom (3, 15, 1000));
  if (randomUtils.possible (50, 100)) {
    if (randomUtils.possible (50, 100)) {
      clickUtils.clickPointMap (pointMap.首页.商城);
    }
    sleep (randomUtils.getRandom (10, 30, 1000));
  } else {
    logUtils.info ('结束观看视频,将关闭今日头条');
    if (randomUtils.possible (50, 100)) {
      clickUtils.clickPointMap (pointMap.首页.我的);
      sleep (randomUtils.getRandom (3, 15, 1000));
    } else {
      sleep (randomUtils.getRandom (3, 15, 1000));
    }
  }
};
touTiao.inTask = function () {
  var content = '开心收下';
  if (clickContent (content)) {
    sleep (randomUtils.getRandom (2, 10, 1000));
  }
};
touTiao.read = function (span) {
  var baseSpan = 10;
  var span = randomUtils.getRandom (baseSpan, baseSpan + 20);
  logUtils.info ('将read ：', span, '秒');
  sleep (span * 1000);
  return;
};

module.exports = touTiao;
